<template>
  <div class="headser" :style="style">
    <div class="zhongjians">
      <div class="header-logo">
        <router-link to="/">
          <p>{{ R.logo.text }}</p>
        </router-link>
      </div>
      <div class="header-menu">
        <ul>
          <li v-for="(i, index) in R.menu" :key="index">
            <div class="header-menu-link">
              <router-link to="" @click="scrollGo(i.url)">{{
                i.text
              }}</router-link>
            </div>
          </li>
        </ul>
      </div>
      <div class="touxiangs">
        <span @click="dialogTableVisible = true">登录</span>
        |
        <span @click="dialogregister = true">注册</span>
      </div>
    </div>
  </div>

  <el-dialog v-model="dialogTableVisible" title="登录" width="25%">
    <loginVue @hello="checkLoRe" />
  </el-dialog>
  <el-dialog v-model="dialogregister" title="注册" width="25%">
    <registerVue @hello="rollasCheck" />
  </el-dialog>
  <transition name="el-zoom-in-top">
    <el-backtop :right="50" :bottom="50" />
  </transition>
</template>

<script lang="ts">
import R from "@/units/Rookies";
import { defineComponent, ref, reactive, toRefs } from "vue";
import loginVue from "../login/login.vue";
import registerVue from "../login/register.vue";
export default defineComponent({
  components: { loginVue, registerVue },
  setup() {
    let dialogTableVisible = ref<boolean>(false);
    let dialogregister = ref<boolean>(false);
    let isbools = ref<boolean>(false);
    let p = reactive({
      style: {
        "box-shadow": "0 0 0px",
      },
    });
    function scrollGo(dom) {
      if (
        !dom.includes("##") ||
        !document.querySelector(dom.substring(1, dom.length))
      ) {
        return;
      }
      window.scrollTo({
        top:
          document.querySelector(dom.substring(1, dom.length)).offsetTop -
          document.querySelector(".headser").clientHeight,
        behavior: "smooth", //这个属性实现滑动效果的
      });
    }
    function show(): void {
      window.addEventListener("scroll", (e) => {
        // console.log(e);
        let gundo =
          document.documentElement.scrollTop || document.body.scrollTop;
        if (gundo > document.querySelector(".headser").clientHeight * 5) {
          p.style["box-shadow"] = "0 0 20px var(--boxColor)";
        } else {
          p.style["box-shadow"] = "";
        }
      });
    }
    show();
    const checkLoRe = (): void => {
      dialogTableVisible.value = false;
      dialogregister.value = true;
    };
    const rollasCheck = (): void => {
      dialogTableVisible.value = true;
      dialogregister.value = false;
    };
    return {
      R,
      scrollGo,
      isbools,
      ...toRefs(p),
      dialogTableVisible,
      dialogregister,
      checkLoRe,
      rollasCheck,
    };
  },
});
</script>

<style lang="less" scoped>
.headser {
  width: 100%;
  height: 1rem;
  line-height: 1rem;
  background-color: var(--bgColor);
  display: flex;
  justify-content: center;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 99;
  // box-shadow: 0 0 10px #666;
  transition: box-shadow 0.3s ease;
  .zhongjians {
    width: 15rem;
    display: flex;

    .header-logo {
      flex: 5;
      p {
        font-size: 0.4rem;
        letter-spacing: 0.1rem;
        color: var(--fontColor);
      }
    }
    .header-menu {
      flex: 5;
      ul {
        display: flex;
        justify-content: space-between;
        li {
          flex: 1;
          height: 100%;
          width: 100%;
          text-align: center;
          .header-menu-link {
            position: relative;
            ::before {
              transition: all 0.7s ease;
              -webkit-transition: all 0.3s ease;
              content: ">";
              display: block;
              position: absolute;
              top: 0;
              opacity: 0;
              left: -0.1rem;
            }

            ::after {
              transition: all 0.7s ease;
              -webkit-transition: all 0.3s ease;
              content: "<";
              display: block;
              position: absolute;
              top: 0;
              opacity: 0;
              right: -0.1rem;
            }
            &:hover {
              position: relative;
              a {
                color: var(--HoverColor);
              }
              ::before {
                content: ">";
                display: inline-block;
                position: absolute;
                left: 0rem;
                top: 0;
                opacity: 1;
              }
              ::after {
                content: "<";
                display: inline-block;
                position: absolute;
                right: 0rem;
                top: 0;
                opacity: 1;
              }
            }
          }
          a {
            color: var(--fontColor);
            font-size: 0.22rem;
          }
        }
      }
    }
    .touxiangs {
      flex: 1;
      margin-left: 1rem;
      color: var(--fontColor);
      span {
        cursor: pointer;
        &:hover {
          color: var(--HoverColor);
        }
      }
    }
  }
}
.shangcs {
  position: fixed;
  right: 0.1rem;
  bottom: 0.1rem;
  height: 0.5rem;
  width: 0.5rem;
  cursor: pointer;
  z-index: 999;
  background-color: red;
}
.transition-box {
  margin-bottom: 10px;
  width: 200px;
  height: 100px;
  border-radius: 4px;
  background-color: #409eff;
  text-align: center;
  color: #fff;
  padding: 40px 20px;
  box-sizing: border-box;
  margin-right: 20px;
}
</style>